<?php

namespace Modules\User\Http\Controllers\Client\V1;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

use Modules\User\Entities\UserGroupPrice;

use Auth;
use Validator;
use ThrowException;

class GroupPriceController extends Controller
{
    // 地址列表
    public function show(Request $req, $uuid)
    {
        $rule = [
        ];
        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest();

        $user = Auth::requireLoginUser();

        $groupPrice = UserGroupPrice::getEntity([
            'uuid' => $uuid
        ]);

        $group = $groupPrice->group;
        if (!$group) {
            ThrowException::Conflict('用户分组不存在');
        }

        $info = $groupPrice->getInfo([
            'id',
            'uuid',
            'title',
            'money_price',
            'score_price'
        ]);

        // $group->

        list($isPassed, $options) = $group->checkRule($user);

        return [
            'info' => $info,
            'is_passed' => $isPassed,
            'options' => $options
        ];
    }
}
